/*
 * Copyright(c) 2020-2100 万达信息股份有限公司 版权所有
 * WONDERS INFORMATION CO., LTD. ALL RIGHTS RESERVED.
 */

package com.wondersgroup;

/**
 * @author: huym
 * @version: 1.0
 * @date: 2020/12/9
 */
public class Sorter<T> {
    public void sort(T[] arr, Comparator<T> comparator){
        for (int i=0;i<arr.length-1;i++){
            int minPos = i;
            for (int j=i+1;j<arr.length;j++){
                minPos = comparator.compareTo(arr[minPos],arr[j])>0 ? j : minPos;
            }
            swap(arr,i,minPos);
        }
    }

    void swap(T[] arr, int i, int j){
        T temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}